package set;

import org.junit.Test;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @Author wangzhipeng
 * @Date 2020-08-13 11:09 上午
 * @Description
 */
public class demo {

    @Test
    public void test1(){
        Set<String> set = new HashSet<>();
        set.add("111");
        set.add("555");
        System.out.println(set);
    }

    @Test
    public void test2(){
        Set<String> set = new HashSet<>();
        set.add("111");
        set.add("555");
        System.out.println(set);
        set.remove("111"); //removeAll  全部删除
        System.out.println(set);
        
    }

    @Test
    public void test3(){
        Set<String> set = new HashSet<>();
        set.add("111");
        set.add("555");
        if(set.contains("555")){
            System.out.println("包含555");
        }
        Iterator<String> iterator = set.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }

    }

    @Test
    public void test4(){
        Set<String> set = new HashSet<>();
        set.add("111");
        set.add("555");
        if(set.add("111")){
            System.out.println("111添加成功");
        }else{
            System.out.println("111添加失败");//因为已存在
        }
        if(set.add("333")){
            System.out.println("333添加成功");
        }
        System.out.println(set);

    }



    
}
